package com.example.android2019.homework.homework4;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

import com.example.android2019.R;

public class BeautyActivity extends AppCompatActivity {
    private ImageView image_beauty;
    private RadioGroup radio_beauty;
    private RadioButton rb, gxt;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        /*关联布局文件*/
        setContentView(R.layout.activity_beauty);
        /*关联控件*/
        inti();
         /* 单选按钮选中事件 OnCheckedChangeListener */
         RadioGroup.OnCheckedChangeListener check=new RadioGroup.OnCheckedChangeListener() {
             @Override
             public void onCheckedChanged(RadioGroup group, int checkedId) {
                  /* 参数checkedId ：表示点击的是哪个单选按钮（ID） */
                  switch (checkedId){
                      case R.id.rb:
                          image_beauty.setImageResource(R.drawable.rb);
                          Toast.makeText(BeautyActivity.this,"热巴+1",Toast.LENGTH_SHORT).show();
                          break;
                      case R.id.gxt:
                          image_beauty.setImageResource(R.drawable.gxt);
                          Toast.makeText(BeautyActivity.this,"关晓彤+1",Toast.LENGTH_SHORT).show();
                          break;
                  }
             }
         };
           /* 单选按钮组 绑定 事件*/
           radio_beauty.setOnCheckedChangeListener(check);
           skip();
    }

    private void inti() {
        image_beauty = findViewById(R.id.image_beauty);
        radio_beauty = findViewById(R.id.radio_beauty);
        rb = findViewById(R.id.rb);
        gxt = findViewById(R.id.gxt);
        /*默认显示热巴图片*/
        image_beauty.setImageResource(R.drawable.rb);
        rb.setChecked(true);
    }
    private void skip(){
        /*获取传递的数据*/
        Intent intent = this.getIntent();
        String a = intent.getStringExtra("test");
        Toast.makeText(this, a, Toast.LENGTH_SHORT).show();
    }
}
